<template>
  <div class="comment">
    <el-table :data="fileList" size="small" stripe style="width: 100%;">
      <el-table-column type="index" width="50"></el-table-column>
      <el-table-column label="点评内容" prop="content" min-width="200" align="left"></el-table-column>
      <el-table-column label="点评分数(分)" prop="score" min-width="100" align="left">
          <template slot-scope="{ row }">
              <span style="color: red;">{{ row.score}}</span>
            </template>
      </el-table-column>
      <el-table-column label="点评人" prop="owner" min-width="100" align="left"></el-table-column>
      <el-table-column label="点评时间" prop="abstract" min-width="150" align="left">
        <template slot-scope="{ row }">
          {{ parseTime(row.create_time) }}
        </template>
      </el-table-column>
      <el-table-column label="操作" min-width="150" align="left">
        <template slot-scope="{ row }">
          <el-button type="text" :disabled="userId == row.owner_id ? false : true" icon="el-icon-delete" @click="handleDeletHistory(row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>
<script>
  import { mapGetters } from 'vuex'
  import { getHistoryUpFile, delHasFile, postFileComment,deleteHistory } from '@/api/work.js'
  import { getFileType, parseTime, previewFile } from '@/utils/index.js'
  export default {
    name: 'HistoryFile',
    props:{
        fileComments: {
            type: Array,
            default () {
                return []
            }
        },
        handleCancelVisible:Function
    },
    data() {
      return {
        fileList:[],
        userId:null,
      }
    },
    watch: {
    fileComments: {
      handler: function(val) {
        this.fileList = val
      },
      immediate: true
    }
  },
    created() {
      // this.fetchMarkInfo()
      this.userId = this.$store.state.user.id
    },
    computed: {
      ...mapGetters([
          'id'
      ])
    },
    methods: {
      parseTime,
      async handleDeletHistory(row){
          // console.log('row',row)
          const res = await deleteHistory(row.id)
          if(res){
            this.$message.success('删除成功')
          }
          //假删除
          let arr = []
          this.fileList.forEach(el =>{
            if(el.id != row.id){
              arr.push(el)
            }
          })
          this.fileList = arr
          this.$emit('fetchHistoryFile')
          // this.handleCancelVisible()
      }
    }
}
</script>
<style>
.comment{
    margin-bottom: 10px;
}
</style>
